package com.xiaobai.waitAndNodify;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadWait {
    public static void main(String[] args) {
        Object o = new Object();
//        try {
//            /*
//            Exception in thread "main" java.lang.IllegalMonitorStateException: current thread is not owner
//            at java.base/java.lang.Object.wait(Native Method)
//            at java.base/java.lang.Object.wait(Object.java:338)
//            at com.xiaobai.waitAndNodify.ThreadWait.main(ThreadWait.java:10)
//             */
//            //wait是需要线程拥有者才能使用的
//            o.wait();
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        synchronized (o){
            try {
                //这个才能进行wait等待 进行monitor里面的waitset里面
                o.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
